package de.rj.urwalking.loader;

import routing.googleadapter.GoogleKMLParser;
import routing.googleadapter.GoogleRoutingAdapter;
import android.content.Context;

import com.google.android.gms.maps.model.LatLng;

import de.rose_mobil.models.route.Route;

/**
 * Used to asynchronously load a route from Google Directions API. 
 * 
 * @author rjj
 * 
 */
public class RouteLoader extends AsyncLoader<Route> {

	private LatLng start;
	private LatLng destination;

	public RouteLoader(Context context, LatLng start, LatLng destination) {
		super(context);
		this.start = start;
		this.destination = destination;
	}

	@Override
	public Route loadInBackground() {
		String xml = GoogleRoutingAdapter.getGoogleRouteAsKML(start, destination);
		GoogleKMLParser kml = new GoogleKMLParser(xml);
		return kml.getWaypoints();
	}
}
